package tmhprediction.optimization;

import java.io.File;
import java.util.HashMap;

import tmhprediction.classification.TMHClassifier;
import tmhprediction.eval.TMHHelixEvaluator;
import tmhprediction.eval.TMHResidueEvaluator;
import tmhprediction.eval.WriteOutput;
import tmhprediction.main.TMHResultMap;

public class GridSearchRunnerSingleSet {

	/**
	 * @param args
	 */
		public static void main(String[] args) throws Exception
		{
			double c = Double.valueOf(args[0]);
			double g = Double.valueOf(args[1]);
			String outFolder = args[2];
			String train = args[3];
			String test = args[4];
			String index = args[5];
			
			c = Math.pow(2.0, c);
			g = Math.pow(2.0, g); 
			
			
			File o = new File(outFolder);
			o.mkdir();
			
			doIt(train, test, null, outFolder,index, c, g);
		}
		
		/***
		 * 
		 * @param trainingSet Pfad zum Arff-file zum trainieren
		 * @param testSet Pfad zum Arff-file zum testen
		 * @param options optionen
		 * @param outFolder
		 * @param index
		 * @param c
		 * @param g
		 * @throws Exception
		 */
		static void doIt(String trainingSet, String testSet, String[] options, String outFolder, String index, double c, double g) throws Exception
		{
			TMHClassifier classifier = new TMHClassifier(trainingSet, testSet, g,c );
			System.out.println("Running with C:"+classifier.getcost() +" and gamma:"+classifier.getGamma() + ". Train and test are: "+trainingSet+" "+testSet);

			System.out.println("Training done, now classification and evaluation");
			TMHResultMap resM = classifier.createResultMap();
			
			System.out.println("Calculate per residue scores");
			TMHResidueEvaluator.calcPerResidueScores(resM, outFolder+"/"+index+"_scoresPerRes");
			
			System.out.println("Writing out predictions in human readable format");
			WriteOutput.writeObservedAndPredicted(resM, outFolder+"/"+index+"_readablePrediction");
			
			System.out.println("Calculating and writing out per segment scores");
			TMHHelixEvaluator.berechneFormeln(TMHHelixEvaluator.finalHelixEvaluation(resM), outFolder+"/"+index+"_scoresPerSeg");

			classifier.saveModel(outFolder+"/"+index+"_model.svm");
			System.out.println("Model saved (for realz!)");
			
		}

	}
